//###############
// FILE : ANDOperator.java
// WRITER : Lior Zimmerman liorz06 066462300
// WRITER : Ohad Dan ohad_dan 036767960
// EXERCISE : oop ex3 2008
// DESCRIPTION:
//  Representation of the binary logic operator AND.
//###############
package oop.ex3.fileSearchModel.filters;
import oop.ex3.fileSearchModel.filters.exceptions.*;
/**
 * Representation of the binary logic operator AND.
 */
public class ANDOperator extends LogicOperator {
	/**
	 * Constructs a new AND logic operator.
	 */
    public ANDOperator(){
    	super();
    }
    /**
     * Constructs a new AND logic operator.
     * @param right Right child.
     * @param left Left child.
     * @param status Status of condition.
     */
    public ANDOperator( Conditionable right, Conditionable left,
    		STATUS status) {
    	super(right,left,status);
    }
    /**
     * Return the value of the condition.
     * @return Condition's status - True,False,Unknown.
     * @throws FilterDataException In case of an error in filter.
     */
    public STATUS getCondition() throws FilterDataException{
        if ( _leftTerm.getCondition() == STATUS.FALSE || 
                _rightTerm.getCondition() == STATUS.FALSE ) {
            return STATUS.FALSE;
        }else if (  _leftTerm.getCondition() == STATUS.TRUE &&
                _rightTerm.getCondition() == STATUS.TRUE) {
            return STATUS.TRUE;
        }
        return STATUS.UNKNOWN;
    }
    /**
     * Clones the object - return a new object with same properties.
     * @return logicOperator
     */
    public LogicOperator clone() {
    	return new ANDOperator( _rightTerm, _leftTerm, _status );
    }
}
